package com.etc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etc.entity.Patient;
import com.etc.mapper.PatientMapper;
import com.etc.service.PatientService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {
    @Resource
    private PatientMapper patientMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return patientMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Patient record) {
        Date date = new Date();
        // 设置创建时间和更新时间 为当前时间
        record.setCreateTime(date);
        record.setUpdateTime(date);
        // 设置是否删除为 0 表示未删
        record.setIsDeleted(Byte.valueOf("0"));
        return patientMapper.insert(record);
    }

    @Override
    public int insertSelective(Patient record) {
        Date date = new Date();
        // 设置创建时间和更新时间 为当前时间
        record.setCreateTime(date);
        record.setUpdateTime(date);
        // 设置是否删除为 0 表示未删
        record.setIsDeleted(Byte.valueOf("0"));
        return patientMapper.insertSelective(record);
    }

    @Override
    public Patient selectByPrimaryKey(Long id) {
        return patientMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Patient record) {
        // 设置更新时间为当前时间
        record.setUpdateTime(new Date());
        return patientMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Patient record) {
        return patientMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Patient> selectAll() {
        return patientMapper.selectAll();
    }
}

